/* Copyright © 2006 Sarp Arda Coskun.
* Contact e-mail: sacoskun@gmail.com

* This file is part of simpleP2P.

* simpleP2P is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License

* simpleP2P is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.

* You should have received a copy of the GNU General Public License
* along with AndPishti.  If not, see <http://www.gnu.org/licenses/>.
*/

/*
 * P2P Server Program
 * Server program of P2P application.

 * Author: Sarp Arda Coskun - 20201238
 * Date: 18 October 2006 with Eclipse 3.1
 * Version: 0.1 (Beta)
 * Tested on : 20 October 2006 with SuSE 10.0 Linux
 */

import java.util.*;
import java.io.*;
import java.net.*;

public class P2PServer
{
	public static void main(String[] args) throws IOException
	{
		// Properties
		boolean listening = true;
		ServerSocket welcomeSocket = null;
		ArrayList files = new ArrayList();
		ArrayList users = new ArrayList();
		int serverPort = Integer.parseInt(args[0]);
		
        try
        {
        	welcomeSocket = new ServerSocket(serverPort);
        }
        catch (IOException e) 
        {
            System.err.println("Could not listen the port.");
            System.exit(-1);
        }		
		
		
		while(listening)
		{
			// Server is waiting for a new client.
			System.out.println("Server is waiting for a client");
		    new ServerThread(welcomeSocket.accept()).start();
		}
		
		// Closes the port.
		welcomeSocket.close();
	}


}

